package service.impl;

import java.util.List;

import dao.EmpDao;
import dao.impl.EmpDaoImpl;
import entity.Emp;
import service.EmpService;

public class EmpServiceImpl implements EmpService{

	EmpDao dao = new EmpDaoImpl();
	
	@Override
	public String save(Emp emp) {
		boolean res = dao.insert(emp);
		return res ? "/success.html" : "/error.html";
	}

	@Override
	public String update(Emp emp) {
		boolean res = dao.update(emp);
		return res ? "/success.html" : "/error.html";
	}

	@Override
	public String remove(int empno) {
		boolean res = dao.deleteById(empno);
		return res ? "/success.html" : "/error.html";
	}

	@Override
	public String getEmp(int empno) {
		Emp emp = dao.selectById(empno);
		System.out.println(emp);
		return emp != null? "/success.html" : "/error.html";
	}

	@Override
	public String getAll() {
		List<Emp> emps = dao.selectAll();
		emps.forEach(System.out::println);
		return emps.isEmpty() == false ? "/success.html" : "/error.html";
	}
}
